---@class BuffEffect43 : BaseBuffEffect
BuffEffect43 = ClientFight.CreateClass("BuffEffect43", ClientFight.BaseBuffEffect)
local t = BuffEffect43

---@param fight Fight
---@param buff FighterBuff
function t:action(fight, buff, ...)
    local buffEffectValue = buff.buffBean.f_BuffEffectValue
    local calculatorType = buffEffectValue[1];
    local plus = buffEffectValue[2];

    local calculator = nil;
    if (calculatorType == 0) then
        calculator = buff.source
    elseif calculatorType == 1 then
        calculator = buff.target
    elseif calculatorType == 2 then
        calculator = buff.skill.target
    elseif calculatorType == 3 then
        calculator = buff.skill.parentSkill.target
    end
    if (calculator == nil) then
        return IBuffEffect.FAIL;
    end
    local isSelf = calculator == buff.target
    for  i = 3, #buffEffectValue, 2 do
        if (#buffEffectValue < i+1) then
            break;
        end
        local attrType = buffEffectValue[i];
        local attrRatio = buffEffectValue[i + 1];
        if (isSelf) then
            attrType = self:convSelf(attrType);
            buff.attributes:changeAttribute(attrType, attrRatio * plus);
            local logType = attrType;
            SkillRoleMgr.savePathFile( "[" .. fight.frame .. "][EFFECT]Fighter " .. buff.target.fighterId .. " Buff"
            .. buff.modelId .. " 触发属性变化, " .. logType .." = " .. attrRatio * plus);
        else
            attrType = self:convOther(attrType);
            if (self:needToRatio(attrType)) then
                local attrValue = FighterAttributeManager.getFightAttr(calculator, attrType);
                attrValue = calcRatio(attrValue, attrRatio);
                buff.attributes:changeAttribute(attrType, attrValue * plus);

                local logType = attrType;
                local logattrValue = attrValue;
                SkillRoleMgr.savePathFile( "[" .. fight.frame .. "][EFFECT]Fighter " .. buff.target.fighterId .. " Buff"
                .. buff.modelId .. " 触发属性变化, " .. logType .." = " .. logattrValue * plus);
            else
                --实际上, 偷别人属性,或别人给自己增加他的xx属性, 是不会走到这个地方来的, 都是走了else 上面的逻辑了
                --因为, 你不可能偷 别人的 n% 的命中, 基本上都是 别人命中 -N   你直接加 N , 因为命中本来就是个百分比的数值类型
                buff.attributes:changeAttribute(attrType, attrRatio * plus);
                local logType = attrType;
                SkillRoleMgr.savePathFile( "[" .. fight.frame .. "][EFFECT]Fighter " .. buff.target.fighterId .. " Buff"
                .. buff.modelId .. " 触发属性变化, " .. logType .. " = " .. attrRatio * plus);
            end
        end
    end

    ClientFight.BaseBuffEffect.action(self,fight, buff, ...);
    return IBuffEffect.SUCCESS_ATTRI_HAS_CHANGE;
end
function t:convSelf(attrType)
    if attrType == FighterAttributeEnum.HP.id then
        return FighterAttributeEnum.HP_PER.id
    elseif attrType == FighterAttributeEnum.ATK.id then
        return FighterAttributeEnum.ATK_PER.id
    elseif attrType == FighterAttributeEnum.DEF.id then
        return FighterAttributeEnum.DEF_PER.id
    end
    return attrType
end
function t:convOther(attrType)
    if attrType == FighterAttributeEnum.HP_PER.id then
        return FighterAttributeEnum.HP.id
    elseif attrType == FighterAttributeEnum.ATK_PER.id then
        return FighterAttributeEnum.ATK.id
    elseif attrType == FighterAttributeEnum.DEF_PER.id then
        return FighterAttributeEnum.DEF.id
    end
    return attrType
end

function t:needToRatio(attrType)
    return FighterAttributeEnum.HP.id == attrType or FighterAttributeEnum.ATK.id == attrType or FighterAttributeEnum.DEF.id == attrType;
end
t.New()